package com.bawei.week.notice

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.bawei.lib_base.entity.NoticeBeanItem
import com.bawei.lib_base.utils.ApiService
import com.bawei.week.park.ParkDataSource

class NoticeDataSource(val apiService: ApiService) : PagingSource<Int,NoticeBeanItem>(){
    override fun getRefreshKey(state: PagingState<Int, NoticeBeanItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, NoticeBeanItem> {
        return try {
            val pare = params.key ?: 0
            val bean = apiService.getNotice(pare,10)
            val nextPage = if (bean.data.size == 10) pare + 1 else null
            LoadResult.Page(bean.data,null,nextPage)
        }catch (e : Exception){
            LoadResult.Error(e)
        }
    }
}